The Deque class implements a type of list known as a Double Ended Queue. A Deque is quite similar to a List, in that items have indices (starting at 0), and the item at any index can be efficiently retrieved. The difference between a List and a Deque lies in the efficiency of inserting elements at the beginning. In a List, items can be efficiently added to the end, but inserting an item at the beginning of the List is slow, taking time proportional to the size of the List. In a Deque, items can be added to the beginning or end equally efficiently, regardless of the number of items in the Deque. As a trade-off for this increased flexibility, Deque is somewhat slower than List (but still constant time) when being indexed to get or retrieve elements.
Namespace: Wintellect.PowerCollections
Assembly:
PowerCollections (in PowerCollections.dll)
Syntax
C# |
---|
[SerializableAttribute] public class Deque<T> : ListBase<T>, ICloneable |
Visual Basic (Declaration) |
---|
<SerializableAttribute> _ Public Class Deque(Of T) _ Inherits ListBase(Of T) _ Implements ICloneable |
Visual C++ |
---|
[SerializableAttribute] generic<typename T> public ref class Deque : public ListBase<T>, ICloneable |
Type Parameters
- T
- The type of items stored in the Deque.
Remarks
The Deque class can also be used as a more flexible alternative to the Queue and Stack classes. Deque is as efficient as Queue and Stack for adding or removing items, but is more flexible: it allows access to all items in the queue, and allows adding or removing from either end.
Deque is implemented as a ring buffer, which is grown as necessary. The size of the buffer is doubled whenever the existing capacity is too small to hold all the elements.
Inheritance Hierarchy
Wintellect.PowerCollections..::CollectionBase<(Of <T>)>
Wintellect.PowerCollections..::ListBase<(Of <T>)>
Wintellect.PowerCollections..::Deque<(Of <T>)>